//
//  OfficeLeaveListCell.swift
//  EduManage
//
//  Created by design02 on 16/12/19.
//  Copyright © 2016年 wsl. All rights reserved.
//

import UIKit

class OfficeLeaveListCell: UITableViewCell {

    
    
    var bgView, photoBgView,typeMark: UIView!
    var contentType,titleLabel,contentLabel,nameLabel,timeLabel: UILabel!
    var oneImage: UIImageView!
    var photoCollectionView: UICollectionView!
    
    var dic: JSON!
    
    let imageArray = NSMutableArray()
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    init(dictionary: JSON, reuseIdentifier: String?) {
        self.dic = dictionary
        super.init(style: UITableViewCellStyle.default, reuseIdentifier: reuseIdentifier)
        setupViews()
    }
    
    func setupViews() {
        
        bgView = UIView.init(frame: CGRect.zero)
        bgView.backgroundColor = UIColor.init(hexString: "f6f6f6", alpha: 1)
        
        
        timeLabel = UILabel.init(frame: CGRect.zero)
        timeLabel.font = UIFont.boldSystemFont(ofSize: 14)
        timeLabel.textColor = UIColor.darkText
        timeLabel.textAlignment = NSTextAlignment.left
        
        nameLabel = UILabel.init(frame: CGRect.zero)
        nameLabel.font = UIFont.systemFont(ofSize: 14)
        nameLabel.textColor = UIColor.init(red: 0.310, green: 0.376, blue: 0.510, alpha: 1.00)
        nameLabel.textAlignment = NSTextAlignment.left
        
        photoBgView = UIView.init(frame: CGRect.zero)
        photoBgView.backgroundColor = UIColor.white
        
        contentType = UILabel.init(frame: CGRect.zero)
        contentType.font = UIFont.systemFont(ofSize: 14)
        contentType.textColor = barColor
        contentType.textAlignment = NSTextAlignment.right
        
        typeMark = UIView.init(frame: CGRect.zero)
        
        
        contentLabel = UILabel.init(frame: CGRect.zero)
        
        contentLabel.textAlignment = NSTextAlignment.left
        
        var title = dic["title"].stringValue
        
        var time = dic["leave_nowtime"].stringValue
        let imageUrl = dic["leave_image"].stringValue
        let name = dic["teaname"].stringValue
        let leave_type = dic["leave_type"].stringValue
        
        
        let format = DateFormatter()
        let formatString = "yyyy-MM-dd HH:mm:ss"
        format.dateFormat = formatString
        let array: NSArray = time.components(separatedBy: ".") as NSArray
        var time1 = array.object(at: 0) as! String
        time1 = time1.replacingOccurrences(of: "T", with: " ")
        let date = format.date(from: time1 )
        format.dateFormat = "yyyy年MM月dd日 EEEE"
        time = format.string(from: date!)
        
        timeLabel.text = time
        nameLabel.text = "请假人 " + name
        contentLabel.text = "\(leave_type)"
        
        self.contentView.addSubview(bgView)
        self.contentView.addSubview(photoBgView)
//        self.contentView.addSubview(typeMark)
//        self.contentView.addSubview(contentType)
        self.contentView.addSubview(contentLabel)
        self.contentView.addSubview(timeLabel)
        self.contentView.addSubview(nameLabel)
        
        contentType.textColor = UIColor.init(red: 0.992, green: 0.544, blue: 0.149, alpha: 1)
        contentType.text = "\(leave_type)"
        typeMark.backgroundColor = UIColor.init(red: 0.992, green: 0.544, blue: 0.149, alpha: 1)
        
        
        bgView.frame = CGRect(x: 10, y: 10, width: screenW - 20, height: 110)
        bgView.layer.cornerRadius = 4;
        bgView.layer.shadowOffset = CGSize(width: 0, height: 1);  // 设置阴影的偏移量
        bgView.layer.shadowRadius = 2.0;  // 设置阴影的半径
        bgView.layer.shadowColor = UIColor.lightGray.cgColor; // 设置阴影的颜色为黑色
        bgView.layer.shadowOpacity = 0.8; // 设置阴影的不透明度
        
        timeLabel.frame = CGRect(x: bgView.frame.minX + 10, y: bgView.frame.minY, width: screenW/2, height: 30)
        //类型
        typeMark.frame = CGRect(x: bgView.frame.maxX-15, y: bgView.frame.minY + 5, width: 2, height: 20);
        contentType.frame = CGRect(x: typeMark.frame.minX-110, y: bgView.frame.minY, width: 100, height: 30);
        photoBgView.frame = CGRect(x: bgView.frame.minX, y: timeLabel.frame.maxY, width: bgView.frame.width, height: 50)
        contentLabel.frame = CGRect(x: bgView.frame.minX + 10, y: timeLabel.frame.maxY, width: bgView.frame.width - 20, height: 50)
        nameLabel.frame = CGRect(x: bgView.frame.minX + 10, y: photoBgView.frame.maxY, width: screenW/2, height: 30)
        
        
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
